package week02

// 860. 柠檬水找零
// https://leetcode-cn.com/problems/lemonade-change/

func lemonadeChange(bills []int) bool {
	var coins = [3]int{20, 10, 5}
	var money = make(map[int]int)
	for _, bill := range bills {
		money[bill]++
		switch bill {
		case 5:
		default:
			bill -= 5
			for _, coin := range coins {
				for {
					var ok = false
					if money[coin] > 0 && coin <= bill {
						money[coin]--
						bill-=coin
						ok = true
					}
					if !ok {
						break
					}
				}
				if bill == 0 {
					break
				}
			}
			if bill > 0 {
				return false
			}
		}
	}
	return true
}